package com.ljx.thread.thread03;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/1 9:50
 * @Version 1.0
 */
public class TestDaemon {
	public static void main(String[] args) {
		DaemonThread daemonThread = new DaemonThread();
		/**
		 * 将daemonThread 设置成为守护线程，当用户线程结束后，守护线程自然也就会结束
		 * 不管守护线程是否是比用户线程更多循环次数还是死循环，用户线程结束，守护线程跟着结束
		 */
		daemonThread.setDaemon(true);
		daemonThread.start();
		for (int i = 0; i < 20; i++) {
			System.out.println(Thread.currentThread().getName()+"~~~~~~~~~~~~~~~"+i);
		}
	}
}

class DaemonThread extends Thread{
	@Override
	public void run() {
		for (int i = 0; i < 20; i++) {
			System.out.println(Thread.currentThread().getName()+"~~~~~~~~~~~~~~~"+i);
		}
	}
}